USE [qlnsDB]
/*
	THAM_SO ThamSo_SelectAll
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ThamSo_SelectAll')
DROP PROCEDURE ThamSo_SelectAll
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ThamSo_SelectAll]
AS
BEGIN
	SET NOCOUNT ON;
	SELECT * FROM [dbo].[THAM_SO];
END
/*
	THAM_SO ThamSo_UpdateAll
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ThamSo_UpdateAll')
DROP PROCEDURE ThamSo_UpdateAll
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ThamSo_UpdateAll]
	@NhapToiThieu int,
	@TonToiDa int,
	@TonToiThieu int,
	@NoToiDa float,
	@QD4 int
AS
BEGIN
	SET NOCOUNT ON;
	UPDATE [dbo].[THAM_SO] SET
		[dbo].[THAM_SO].[NhapToiThieu]=@NhapToiThieu,
		[dbo].[THAM_SO].[TonToiDa]=@TonToiDa,
		[dbo].[THAM_SO].[TonToiThieu]=@TonToiThieu,
		[dbo].[THAM_SO].[NoToiDa]=@NoToiDa,
		[dbo].[THAM_SO].[QD4]=@QD4
END
/*
	DAU_SACH DauSach_Cnt_Filter
	Filter DAU_SACH by Ten, The Loai, Tac Gia, Luong Ton
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'DauSach_Cnt_Filter')
DROP PROCEDURE DauSach_Cnt_Filter
GO
CREATE PROCEDURE DauSach_Cnt_Filter
	@Ten nvarchar(50),
	@TheLoai nvarchar(50),
	@TacGia nvarchar(50),
	@LuongTon varchar(50)
AS
BEGIN
	SET NOCOUNT ON;
-- BEGIN OF SOLUONG
	dECLARE @Value int,@Exp varchar(2),@idx int, @i int;
	sET @i=0;sET @idx=0;
	wHILE @i<5 AND @idx=0
	BEGIN
		IF @i=0 BEGIN SET @Exp='>=' END;
		IF @i=1 BEGIN SET @Exp='<=' END;
		IF @i=2 BEGIN SET @Exp='>' END;
		IF @i=3 BEGIN SET @Exp='<' END;
		IF @i=4 BEGIN SET @Exp='=' END;
		sET @idx=CHARINDEX(@Exp,@LuongTon);
		sET @i=@i+1;
	END
	IF @idx>0 BEGIN
		sET @Value=CAST(SUBSTRING(@LuongTon,@idx+LEN(@Exp),LEN(@LuongTon)-LEN(@Exp)) AS INT);
	END
-- END OF SOLUONG
	(SELECT * INTO TMP_1 FROM [dbo].[DAU_SACH] WHERE 
		UPPER([dbo].[DAU_SACH].[Ten]) like UPPER(@Ten) and 
		UPPER([dbo].[DAU_SACH].[TheLoai]) like UPPER(@TheLoai) and 
		UPPER([dbo].[DAU_SACH].[TacGia]) like UPPER(@TacGia)
	)
	
	IF @idx>0 BEGIN
		IF @Exp='>=' BEGIN
			SELECT COUNT(*) AS SL FROM TMP_1 WHERE [LuongTon] >= @Value;
		END
		ELSE BEGIN IF @Exp='<=' BEGIN
			SELECT COUNT(*) AS SL FROM TMP_1 WHERE [LuongTon] <= @Value;
		END
		ELSE BEGIN IF @Exp='>' BEGIN
			SELECT COUNT(*) AS SL FROM TMP_1 WHERE [LuongTon] > @Value;
		END
		ELSE BEGIN IF @Exp='<' BEGIN
			SELECT COUNT(*) AS SL FROM TMP_1 WHERE [LuongTon] < @Value;
		END
		ELSE BEGIN IF @Exp='=' BEGIN
			SELECT COUNT(*) AS SL FROM TMP_1 WHERE [LuongTon] = @Value;
		END END END END END
	END
	ELSE BEGIN
		SELECT COUNT(*) AS SL FROM TMP_1;
	END

	DROP TABLE TMP_1	 
END
/*
	DAU_SACH DauSach_Cnt_Filter
	Filter DAU_SACH by Ten, The Loai, Tac Gia, Luong Ton
	Return 10 DAU_SACH match Filter
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'DauSach_Filter')
DROP PROCEDURE DauSach_Filter
GO
CREATE PROCEDURE DauSach_Filter
	@Page int,
	@Ten nvarchar(50),
	@TheLoai nvarchar(50),
	@TacGia nvarchar(50),
	@LuongTon varchar(50)
AS
BEGIN
	SET NOCOUNT ON;
-- BEGIN OF SOLUONG
	dECLARE @Value int,@Exp varchar(2),@idx int, @i int;
	sET @i=0;sET @idx=0;
	wHILE @i<5 AND @idx=0
	BEGIN
		IF @i=0 BEGIN SET @Exp='>=' END;
		IF @i=1 BEGIN SET @Exp='<=' END;
		IF @i=2 BEGIN SET @Exp='>' END;
		IF @i=3 BEGIN SET @Exp='<' END;
		IF @i=4 BEGIN SET @Exp='=' END;
		sET @idx=CHARINDEX(@Exp,@LuongTon);
		sET @i=@i+1;
	END
	IF @idx>0 BEGIN
		sET @Value=CAST(SUBSTRING(@LuongTon,@idx+LEN(@Exp),LEN(@LuongTon)-LEN(@Exp)) AS INT);
	END
-- END OF SOLUONG
	DECLARE @n int, @startRow int, @endRow int;
	SET @n = 10;
	SET @startRow = ((@Page-1)*@n)+1;
	SET @endRow = @startRow + @n - 1;
	
	(SELECT * INTO TMP_1 FROM [dbo].[DAU_SACH] WHERE 
		UPPER([dbo].[DAU_SACH].[Ten]) like UPPER(@Ten) and 
		UPPER([dbo].[DAU_SACH].[TheLoai]) like UPPER(@TheLoai) and 
		UPPER([dbo].[DAU_SACH].[TacGia]) like UPPER(@TacGia)
	)
	
	IF @idx>0 BEGIN
		IF @Exp='>=' BEGIN
			SELECT * INTO TMP_2 FROM TMP_1 WHERE [LuongTon] >= @Value;
		END
		ELSE BEGIN IF @Exp='<=' BEGIN
			SELECT * INTO TMP_2 FROM TMP_1 WHERE [LuongTon] <= @Value;
		END
		ELSE BEGIN IF @Exp='>' BEGIN
			SELECT * INTO TMP_2 FROM TMP_1 WHERE [LuongTon] > @Value;
		END
		ELSE BEGIN IF @Exp='<' BEGIN
			SELECT * INTO TMP_2 FROM TMP_1 WHERE [LuongTon] < @Value;
		END
		ELSE BEGIN IF @Exp='=' BEGIN
			SELECT * INTO TMP_2 FROM TMP_1 WHERE [LuongTon] = @Value;
		END END END END END
	END
	ELSE BEGIN
		SELECT * INTO TMP_2 FROM TMP_1;
	END

	DROP TABLE TMP_1

	SELECT [ID],[Ten],[TheLoai],[TacGia],[LuongTon] FROM
	(SELECT *, ROW_NUMBER() OVER (ORDER BY [ID]) AS RowNum FROM TMP_2 AS TMP_3) AS TMP_4
	WHERE RowNum BETWEEN @startRow AND @endRow

	DROP TABLE TMP_2
END
/*
	DAU_SACH DauSach_SelectByID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'DauSach_SelectByID')
DROP PROCEDURE DauSach_SelectByID
GO
CREATE PROCEDURE DauSach_SelectByID
	@ID int
AS
BEGIN
	SET NOCOUNT ON;
	SELECT * FROM [dbo].[DAU_SACH] WHERE [dbo].[DAU_SACH].[ID] = @ID
END
/*
	DAU_SACH DauSach_UpdateByID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'DauSach_UpdateByID')
DROP PROCEDURE DauSach_UpdateByID
GO
CREATE PROCEDURE DauSach_UpdateByID
	@ID int,
	@Ten nvarchar(50),
	@TheLoai nvarchar(50),
	@TacGia nvarchar(50),
	@LuongTon int
AS
BEGIN
	SET NOCOUNT ON;
	UPDATE [dbo].[DAU_SACH] SET 
		[dbo].[DAU_SACH].[Ten] = @Ten,
		[dbo].[DAU_SACH].[TheLoai] = @TheLoai,
		[dbo].[DAU_SACH].[TacGia] = @TacGia,
		[dbo].[DAU_SACH].[LuongTon] = @LuongTon
	WHERE [dbo].[DAU_SACH].[ID] = @ID
END
/*
	DAU_SACH Insert
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'DauSach_Insert')
DROP PROCEDURE DauSach_Insert
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DauSach_Insert]
	@Ten nvarchar(50),
	@TheLoai nvarchar(50),
	@TacGia nvarchar(50),
	@LuongTon int
AS
BEGIN
	DECLARE @Retval INT
	SET NOCOUNT ON;
	INSERT INTO [dbo].[DAU_SACH]
	([Ten],[TheLoai],[TacGia],[LuongTon])
	VALUES
	(@Ten,@TheLoai,@TacGia,@LuongTon);
	SELECT @Retval = MAX([dbo].[DAU_SACH].[ID]) FROM [dbo].[DAU_SACH];
	RETURN @Retval;
END
/*
	DAU_SACH DauSach_SelectByTenTacGiaTheLoai
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'DauSach_SelectByTenTacGiaTheLoai')
DROP PROCEDURE DauSach_SelectByTenTacGiaTheLoai
GO
CREATE PROCEDURE DauSach_SelectByTenTacGiaTheLoai
	@Ten nvarchar(50),
	@TheLoai nvarchar(50),
	@TacGia nvarchar(50)
AS
BEGIN
	SET NOCOUNT ON;
	SELECT * FROM [dbo].[DAU_SACH] WHERE [dbo].[DAU_SACH].[Ten] = @Ten and
			[dbo].[DAU_SACH].[TheLoai] = @TheLoai and
			[dbo].[DAU_SACH].[TacGia] = @TacGia
END
/*
	PHIEU_NHAP_SACH Insert
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'PhieuNhapSach_Insert')
DROP PROCEDURE PhieuNhapSach_Insert
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PhieuNhapSach_Insert]
	@NgayNhap DATETIME
AS
BEGIN
	DECLARE @Retval INT
	SET NOCOUNT ON;
	INSERT INTO [dbo].[PHIEU_NHAP_SACH]
	([NgayNhap])
	VALUES
	(@NgayNhap);
	SELECT @Retval = MAX([dbo].[PHIEU_NHAP_SACH].[ID]) FROM [dbo].[PHIEU_NHAP_SACH];
	RETURN @Retval;
END
/*
	CHI_TIET_NHAP_SACH Insert
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ChiTietNhapSach_Insert')
DROP PROCEDURE ChiTietNhapSach_Insert
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ChiTietNhapSach_Insert]
	@IDPhieuNhap int,
	@IDSach int,
	@SoLuong int
AS
BEGIN
	DECLARE @Retval INT
	SET NOCOUNT ON;
	INSERT INTO [dbo].[CHI_TIET_NHAP_SACH]
	([IDPhieuNhap],[IDSach],[SoLuong])
	VALUES
	(@IDPhieuNhap,@IDSach,@SoLuong);
	SELECT @Retval = 1;
	RETURN @Retval;
END
/*
	KHACH_HANG KhachHang_Cnt_Filter
	Filter KHACH_HANG by Ho Ten, Dia Chi, Dien Thoai, Email
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'KhachHang_Cnt_Filter')
DROP PROCEDURE KhachHang_Cnt_Filter
GO
CREATE PROCEDURE [KhachHang_Cnt_Filter]
	@HoTen nvarchar(50),
	@DiaChi nvarchar(50),
	@DienThoai varchar(50),
	@Email varchar(50)
AS
BEGIN
	SET NOCOUNT ON;
	(SELECT * INTO TMP_1 FROM [dbo].[KHACH_HANG] WHERE 
		UPPER([dbo].[KHACH_HANG].[HoTen]) like UPPER(@HoTen) and 
		UPPER([dbo].[KHACH_HANG].[DiaChi]) like UPPER(@DiaChi) and 
		UPPER([dbo].[KHACH_HANG].[DienThoai]) like UPPER(@DienThoai) and
		UPPER([dbo].[KHACH_HANG].[Email]) like UPPER(@Email)
	)
	SELECT COUNT(*) AS SL FROM TMP_1;
	DROP TABLE TMP_1	 
END
/*
	KHACH_HANG KhachHang_Filter
	Filter KHACH_HANG by Ho Ten, Dia Chi, Dien Thoai, Email
	Return 10 KHACH_HANG match Filter
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'KhachHang_Filter')
DROP PROCEDURE KhachHang_Filter
GO
CREATE PROCEDURE [KhachHang_Filter]
	@Page int,
	@HoTen nvarchar(50),
	@DiaChi nvarchar(50),
	@DienThoai varchar(50),
	@Email varchar(50)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @n int, @startRow int, @endRow int;
	SET @n = 10;
	SET @startRow = ((@Page-1)*@n)+1;
	SET @endRow = @startRow + @n - 1;
	
	(SELECT * INTO TMP_1 FROM [dbo].[KHACH_HANG] WHERE 
		UPPER([dbo].[KHACH_HANG].[HoTen]) like UPPER(@HoTen) and 
		UPPER([dbo].[KHACH_HANG].[DiaChi]) like UPPER(@DiaChi) and 
		UPPER([dbo].[KHACH_HANG].[DienThoai]) like UPPER(@DienThoai) and
		UPPER([dbo].[KHACH_HANG].[Email]) like UPPER(@Email)
	)
	
	SELECT [ID],[HoTen],[DiaChi],[DienThoai],[Email],[DuNo] FROM
	(SELECT *, ROW_NUMBER() OVER (ORDER BY [ID]) AS RowNum FROM TMP_1 AS TMP_2) AS TMP_3
	WHERE RowNum BETWEEN @startRow AND @endRow
	DROP TABLE TMP_1
END
/*
	KHACH_HANG KhachHang_SelectByID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'KhachHang_SelectByID')
DROP PROCEDURE KhachHang_SelectByID
GO
CREATE PROCEDURE [KhachHang_SelectByID]
	@ID int
AS
BEGIN
	SET NOCOUNT ON;
	SELECT * FROM [dbo].[KHACH_HANG] WHERE [dbo].[KHACH_HANG].[ID] = @ID
END
/*
	KHACH_HANG KhachHang_UpdateByID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'KhachHang_UpdateByID')
DROP PROCEDURE KhachHang_UpdateByID
GO
CREATE PROCEDURE [KhachHang_UpdateByID]
	@ID int,
	@HoTen nvarchar(50),
	@DiaChi nvarchar(50),
	@DienThoai varchar(50),
	@Email varchar(50),
	@DuNo float
AS
BEGIN
	SET NOCOUNT ON;
	UPDATE [dbo].[KHACH_HANG] SET 
		[dbo].[KHACH_HANG].[HoTen] = @HoTen,
		[dbo].[KHACH_HANG].[DiaChi] = @DiaChi,
		[dbo].[KHACH_HANG].[DienThoai] = @DienThoai,
		[dbo].[KHACH_HANG].[Email] = @Email,
		[dbo].[KHACH_HANG].[DuNo] = @DuNo
	WHERE [dbo].[KHACH_HANG].[ID] = @ID
END
/*
	KHACH_HANG Insert
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'KhachHang_Insert')
DROP PROCEDURE KhachHang_Insert
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[KhachHang_Insert]
	@HoTen nvarchar(50),
	@DiaChi nvarchar(50),
	@DienThoai varchar(50),
	@Email varchar(50),
	@DuNo float
AS
BEGIN
	DECLARE @Retval INT
	SET NOCOUNT ON;
	INSERT INTO [dbo].[KHACH_HANG]
	([HoTen],[DiaChi],[DienThoai],[Email],[DuNo])
	VALUES
	(@HoTen,@DiaChi,@DienThoai,@Email,@DuNo);
	SELECT @Retval = MAX([dbo].[KHACH_HANG].[ID]) FROM [dbo].[KHACH_HANG];
	RETURN @Retval;
END
/*
	KHACH_HANG KhachHang_SelectByTenDiaChiEmailDienThoai
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'KhachHang_SelectByTenDiaChiEmailDienThoai')
DROP PROCEDURE KhachHang_SelectByTenDiaChiEmailDienThoai
GO
CREATE PROCEDURE [KhachHang_SelectByTenDiaChiEmailDienThoai]
	@HoTen nvarchar(50),
	@DiaChi nvarchar(50),
	@DienThoai varchar(50),
	@Email varchar(50)
AS
BEGIN
	SET NOCOUNT ON;
	SELECT * FROM [dbo].[KHACH_HANG] WHERE [dbo].[KHACH_HANG].[HoTen] = @HoTen and
			[dbo].[KHACH_HANG].[DiaChi] = @DiaChi and
			[dbo].[KHACH_HANG].[DienThoai] = @DienThoai and
			[dbo].[KHACH_HANG].[Email] = @Email
END
/*
	CHI_TIET_BAN_SACH Insert
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ChiTietBanSach_Insert')
DROP PROCEDURE ChiTietBanSach_Insert
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ChiTietBanSach_Insert]
	@IDSach int,
	@IDHoaDon int,
	@SoLuong int,
	@DonGia float
AS
BEGIN
	DECLARE @Retval INT
	SET NOCOUNT ON;
	INSERT INTO [dbo].[CHI_TIET_BAN_SACH]
	([IDSach],[IDHoaDon],[SoLuong],[DonGia])
	VALUES
	(@IDSach,@IDHoaDon,@SoLuong,@DonGia);
	SELECT @Retval = 1;
	RETURN @Retval;
END
/*
	HOA_DON_BAN_SACH Insert
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'HoaDonBanSach_Insert')
DROP PROCEDURE HoaDonBanSach_Insert
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[HoaDonBanSach_Insert]
	@IDKhachHang int,
	@NgayLap DATETIME
AS
BEGIN
	DECLARE @Retval INT
	SET NOCOUNT ON;
	INSERT INTO [dbo].[HOA_DON_BAN_SACH]
	([IDKhachHang],[NgayLap])
	VALUES
	(@IDKhachHang,@NgayLap);
	SELECT @Retval = MAX([dbo].[HOA_DON_BAN_SACH].[ID]) FROM [dbo].[HOA_DON_BAN_SACH];
	RETURN @Retval;
END
/*
	PHIEU_THU Insert
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'PhieuThu_Insert')
DROP PROCEDURE PhieuThu_Insert
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PhieuThu_Insert]
	@IDKhachHang int,
	@NgayThu DATETIME,
	@SoTien float
AS
BEGIN
	DECLARE @Retval INT
	SET NOCOUNT ON;
	INSERT INTO [dbo].[PHIEU_THU]
	([IDKhachHang],[NgayThu],[SoTien])
	VALUES
	(@IDKhachHang,@NgayThu,@SoTien);
	SELECT @Retval = MAX([dbo].[PHIEU_THU].[ID]) FROM [dbo].[PHIEU_THU];
	RETURN @Retval;
END
/*
	BAO_CAOT_TON_THANG Insert
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'BaoCaoTonThang_Insert')
DROP PROCEDURE BaoCaoTonThang_Insert
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BaoCaoTonThang_Insert]
	@Thang int,
	@IDSach int,
	@TonDau int,
	@TonCuoi int,
	@PhatSinh int
AS
BEGIN
	DECLARE @Retval INT
	SET NOCOUNT ON;
	INSERT INTO [dbo].[BAO_CAO_TON_THANG]
	([Thang],[IDSach],[TonDau],[TonCuoi],[PhatSinh])
	VALUES
	(@Thang,@IDSach,@TonDau,@TonCuoi,@PhatSinh);
	SELECT @Retval = @Thang;
	RETURN @Retval;
END
/*
	BAO_CAOT_TON_THANG Insert
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'BaoCaoNoThang_Insert')
DROP PROCEDURE BaoCaoNoThang_Insert
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BaoCaoNoThang_Insert]
	@Thang int,
	@IDKhachHang int,
	@NoDau float,
	@NoCuoi float,
	@PhatSinh float
AS
BEGIN
	DECLARE @Retval INT
	SET NOCOUNT ON;
	INSERT INTO [dbo].[BAO_CAO_NO_THANG]
	([Thang],[IDKhachHang],[NoDau],[NoCuoi],[PhatSinh])
	VALUES
	(@Thang,@IDKhachHang,@NoDau,@NoCuoi,@PhatSinh);
	SELECT @Retval = @Thang;
	RETURN @Retval;
END
/*
	PHIEU_NHAP_SACH PhieuNhapSach_SelectAllByNgayNhap
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'PhieuNhapSach_SelectAllByNgayNhap')
DROP PROCEDURE PhieuNhapSach_SelectAllByNgayNhap
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PhieuNhapSach_SelectAllByNgayNhap]
	@NgayNhap DATETIME
AS
BEGIN
	SELECT * FROM [dbo].[PHIEU_NHAP_SACH] WHERE
		YEAR([dbo].[PHIEU_NHAP_SACH].[NgayNhap]) = YEAR(@NgayNhap) and 
		MONTH([dbo].[PHIEU_NHAP_SACH].[NgayNhap]) = MONTH(@NgayNhap) and
		DAY([dbo].[PHIEU_NHAP_SACH].[NgayNhap]) = DAY(@NgayNhap)
END
/*
	CHI_TIET_NHAP_SACH ChiTietNhapSach_SelectAllByPhieuNhap
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ChiTietNhapSach_SelectAllByPhieuNhap')
DROP PROCEDURE ChiTietNhapSach_SelectAllByPhieuNhap
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ChiTietNhapSach_SelectAllByPhieuNhap]
	@IDPhieuNhap int
AS
BEGIN
	SELECT * FROM [dbo].[CHI_TIET_NHAP_SACH] WHERE
		[dbo].[CHI_TIET_NHAP_SACH].[IDPhieuNhap] = @IDPhieuNhap
END
/*
	PHIEU_NHAP_SACH HoaDonBanSach_SelectAllByNgayLap
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'HoaDonBanSach_SelectAllByNgayLap')
DROP PROCEDURE HoaDonBanSach_SelectAllByNgayLap
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[HoaDonBanSach_SelectAllByNgayLap]
	@NgayLap DATETIME
AS
BEGIN
	SELECT * FROM [dbo].[HOA_DON_BAN_SACH] WHERE
		YEAR([dbo].[HOA_DON_BAN_SACH].[NgayLap]) = YEAR(@NgayLap) and 
		MONTH([dbo].[HOA_DON_BAN_SACH].[NgayLap]) = MONTH(@NgayLap) and
		DAY([dbo].[HOA_DON_BAN_SACH].[NgayLap]) = DAY(@NgayLap)
END
/*
	CHI_TIET_BAN_SACH ChiTietBanSach_SelectAllByHoaDon
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ChiTietBanSach_SelectAllByHoaDon')
DROP PROCEDURE ChiTietBanSach_SelectAllByHoaDon
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ChiTietBanSach_SelectAllByHoaDon]
	@IDHoaDon int
AS
BEGIN
	SELECT * FROM [dbo].[CHI_TIET_BAN_SACH] WHERE
		[dbo].[CHI_TIET_BAN_SACH].[IDHoaDon] = @IDHoaDon
END
/*
	PHIEU_THU PhieuThu_SelectAllByNgayLap
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'PhieuThu_SelectAllByNgayThu')
DROP PROCEDURE PhieuThu_SelectAllByNgayThu
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PhieuThu_SelectAllByNgayThu]
	@NgayThu DATETIME
AS
BEGIN
	SELECT * FROM [dbo].[PHIEU_THU] WHERE
		YEAR([dbo].[PHIEU_THU].[NgayThu]) = YEAR(@NgayThu) and 
		MONTH([dbo].[PHIEU_THU].[NgayThu]) = MONTH(@NgayThu) and
		DAY([dbo].[PHIEU_THU].[NgayThu]) = DAY(@NgayThu)
END
/*
	BAO_CAO_TON_THANG BaoCaoTon_SelectAllByThang
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'BaoCaoTon_SelectAllByThang')
DROP PROCEDURE BaoCaoTon_SelectAllByThang
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BaoCaoTon_SelectAllByThang]
	@Thang int
AS
BEGIN
	SELECT * FROM [dbo].[BAO_CAO_TON_THANG] WHERE 
		[dbo].[BAO_CAO_TON_THANG].[Thang] = @Thang
END
/*
	BAO_CAO_NO_THANG BaoCaoNo_SelectAllByThang
	Return ID
*/
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'BaoCaoNo_SelectAllByThang')
DROP PROCEDURE BaoCaoNo_SelectAllByThang
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BaoCaoNo_SelectAllByThang]
	@Thang int
AS
BEGIN
	SELECT * FROM [dbo].[BAO_CAO_NO_THANG] WHERE 
		[dbo].[BAO_CAO_NO_THANG].[Thang] = @Thang
END